<?php
class Support
{
	public $Table="support";
	public $SupportID;
	public $DepartmentName;
	public $Nick;
	public $ChatPro;
	public $Pos;
	
	function loadByKey($id)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` where SupportID='".$id."'";
		$row=$ob->singleData($sql);
		$this->SupportID=$row['SupportID'];
		$this->DepartmentName=$row['DepartmentName'];
		$this->Nick=$row['Nick'];
		$this->ChatPro=$row['ChatPro'];
		$this->Pos=$row['Pos'];
		
	}
	function getTable($dk)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` $dk";
		$data=$ob->mutiData($sql);
		return $data;
	}
	function getListChat()
	{
		$arr=array(
			"1"=>"Yahoo",
			"2"=>"Skype"
		);
		return $arr;
	}
	function getChatProName()
	{
		$arr=$this->getListChat();
		return $arr["".$this->ChatPro];
	}
	function cbChatPro($cbname,$selectvalue)
	{
		$arr=$this->getListChat();
		$cb="<select name='$cbname'>";
		foreach($arr as $key => $val)
		{
			$sel="";
			if($key==$selectvalue)
				$sel="selected";
			$cb.="<option value='".$key."' $sel>".$val."</option>";
		}
		$cb.="</select>";
		return $cb;
	}
	function getNextPos()
	{
		$ob=new ClassConnect();
		$sql="SELECT max(Pos) as max FROM `".$this->Table."`";
		$row=$ob->singleData($sql);
		$max=$row['max'];
		return $max + 1;
	}
	function travel($dk)
	{
		$arr=array();
		$data=$this->getTable($dk);
		for($i=0;$i<count($data);$i++)
			array_push($arr,$data[$i]['SupportID']);
		return $arr;
	}
	function insert($conn)
	{
		$ob=new ClassConnect();
		$this->SupportID=$ob->getNextId($this->Table,"SupportID");
		$field=array("SupportID","DepartmentName","Nick","ChatPro","Pos");
		$value=array($this->SupportID,$this->DepartmentName,$this->Nick,$this->ChatPro,$this->Pos);
		return $ob->insertData($conn,$this->Table,$field,$value);
	}
	function update($conn)
	{
		$ob=new ClassConnect();
		$obj = new Support();
		$field=array("SupportID","DepartmentName","Nick","ChatPro","Pos");
		$value=array($this->SupportID,$this->DepartmentName,$this->Nick,$this->ChatPro,$this->Pos);
		$where="SupportID = '".$this->SupportID."'";
		
		return $ob->updateData($conn,$this->Table,$field,$value,$where);			
	}
	
	function delete($conn)
	{
		$ob=new ClassConnect();	
		$where="SupportID = '".$this->SupportID."'";
		return $ob->deleteData($conn,$this->Table,$where);
			
	}

}
?>
